define(['moment', 'module/moduleMobileSMT/program/SMT02/MaterialStation.service'], function (moment) {
    return ['$scope', '$rootScope', '$mdDialog', 'MMWService', '$filter', '$stateParams', '$timeout', 'config', '$MaterialStation',
        function ($scope, $rootScope, $mdDialog, $MMWService, $filter, $stateParams, $timeout, config, $MaterialStation) {

            // 流程
            var levels = [
                [
                    'process_machine',
                    'process_plot_no',
                    'process_feederlist'
                ],
                [
                    'process_feeder',
                    'process_material',
                    'process_slot_no'
                ]
            ];

            let element_barcode_no;//pda掃描
            $scope.init = function(){
                $scope.user_name = config.cache.name;
                $scope.envInfo = $filter('translate')('Login.env.'+config.setting.environment);
                // 預設流程狀態
                $scope.level_index = 0;
                $scope.phases_index = 0;
                $scope.phases = levels[$scope.level_index];
                //正背板
                $scope.panelList = [{"labelname":$filter('translate')('SMT02.panel.options_1'),"labelval":"1"},{"labelname":$filter('translate')('SMT02.panel.options_2'),"labelval":"2"}];
                $scope.panel_val = $scope.panelList[0].labelval;
                $scope.panel_name =  $scope.panelList[0].labelname;
                //料站
                $scope.select_slot_list = [];
                $scope.select_slot_no = '';
                $scope.disable_control = config.cache.sys_parameter["SMTInfo.SMTPartDisableControl"] //禁用物料卡控
                $scope.barcode = '';
            
                // 自動隱蔽鍵盤
                element_barcode_no = document.getElementById('input_barcode');
                makeBarcodeInput(element_barcode_no);
                element_barcode_no.focus();
            }

            $scope.back = function(){
                $scope.$root.hideMenu();
                $scope.$root.changeProgram('menu', true);
            };

            // QRCode輸入
            $scope.QRCodeScanner = function(){
                $scope.$root.OpenScanner({
                    after : function(result){
                        input_barcode_no_callback(result.text);
                    },
                    exception: function(){
                        //目前裝置無法使用相機
                        $scope.$root.showAlert($filter('translate')('common.msg.cant_use_camera'));
                    },
                    orientation : 'portrait'
                });
            };

            // barcode輸入
            $scope.input_barcode = function(barcode){
                input_barcode_no_callback(barcode);
            };

            // 流程狀態
            $scope.PhaseStatus = function(index){
                if($scope.phases_index > index)
                    return ['prev'];
                else if($scope.phases_index == index)
                    return ['now'];
                else
                    return ['next'];
            }

            // 回上一步流程
            $scope.BackToPhase = function (index){
                if($scope.phases_index > index){
                    if($scope.level_index==1 && index== 1 && $scope.state && $scope.state == '40'){//如果feeder已上料則跑此卡控
                        $scope.$root.showAlert($filter('translate')('SMT.common.msg.feeder_already_feeding'));
                   }else{
                       $scope.phases_index = index;
                        if($scope.level_index == 0 && $scope.phases_index == 0){
                            // 回 設備流程
                            $scope.machine_no = '';
                            $scope.machine_state = '';
                            $scope.plot_no = '';
                            $scope.plot_product_no = '';
                            $scope.plot_item_spec = '';
                            $scope.feederlist_no = '';
                            $scope.feederlist_ver = '';
                            $scope.feederlist = [];
                            // 設備是已上料狀態，只能回到設備流程
                            $scope.machine_state_40 = false;
                        } else if($scope.level_index == 0 && $scope.phases_index == 1){
                            // 回 生產批流程
                            // 設備是已上料狀態，不能修改資料
                            if($scope.machine_state_40 != true){
                                $scope.plot_no = '';
                                $scope.plot_product_no = '';
                                $scope.plot_item_spec = '';
                                $scope.feederlist_no = '';
                                $scope.feederlist_ver = '';
                                $scope.feederlist = [];
                            } else {
                                $scope.phases_index = 2;
                                $scope.$root.showAlert($filter('translate')('SMT03.msg.machine_already_feeding_canNot_modify_data'));
                            };
                        } else if($scope.level_index == 1 && $scope.phases_index == 0){
                            // 回 Feeder流程
                            $scope.feeder_no = '';
                            $scope.feeder_state = '';
                            $scope.material_no = '';
                            $scope.material_product_no = '';
                            $scope.material_item_spec = '';
                            $scope.slot_no = '';
                            $scope.state = ''; 
                            $scope.select_slot_no = '';
                            $scope.select_slot_list = [];
                            $scope.mfg_date = '';
                            $scope.exp_date = '';
                        } else if($scope.level_index == 1 && $scope.phases_index == 1){
                            // 回 物料流程
                            $scope.material_no = '';
                            $scope.material_product_no = '';
                            $scope.material_item_spec = '';
                            $scope.slot_no = '';
                            $scope.select_slot_no = '';
                            $scope.select_slot_list = [];
                            $scope.mfg_date = '';
                            $scope.exp_date = '';
                        }
                   }
                };
            };

            // 切換頁面 ng-class
            $scope.LevelPhaseStatus = function(index){
                return $scope.level_index == 0?'prevPage':'nextPage';
            }

            // 下一頁
            $scope.nextPage = function(){
                if($scope.level_index == 0 && $scope.phases_index == 2){
                    if($scope.feederlist_no ==''){
                        $scope.$root.showAlert($filter('translate')('SMT03.msg.feederlist_empty'));
                    }else{
                        $scope.level_index = 1;
                        $scope.phases_index = 0;
                        $scope.phases = levels[$scope.level_index];
                        $timeout(function(){
                            element_barcode_no.focus();
                        })
                    }
                }
            }

            // 上一頁
            $scope.prevPage = function(){
                if($scope.level_index == 1 && $scope.phases_index == 0){
                    $scope.level_index = 0;
                    $scope.phases_index = 2;
                    $scope.phases = levels[$scope.level_index];
                    $timeout(function(){
                        element_barcode_no.focus();
                    })
                } else {
                    $scope.$root.showConfirm($filter('translate')('SMT03.msg.prev-page_data-disappear'),function(dialog){
                        dialog.hide();
                        $scope.level_index = 0;
                        $scope.phases_index = 2;
                        // 清空 feeder
                        $scope.feeder_no = '';
                        $scope.feeder_state = '';
                        // 清空 物料批
                        $scope.material_no = '';
                        $scope.material_product_no = '';
                        $scope.material_item_spec = '';
                        $scope.select_slot_list = [];
                        $scope.select_slot_no = '';
                        $scope.mfg_date = '';
                        $scope.exp_date = '';
                    })
                }
            }
            //開窗更換正背版
            $scope.loadPanel = function()
            {
                $scope.$root.showSelect({
                    label : 'labelname',
                    code : 'labelval',
                    selectCode : $scope.panel_val,
                    list : $scope.panelList,
                    confirm : function(item, dialog){
                        $scope.panel_val = item.labelval;
                        $scope.panel_name = item.labelname;
                        dialog.hide();
                    }
                });
            };
            $scope.loadSlot = function()
            {
                if($scope.level_index == 1 && $scope.phases_index == 2 && $scope.select_slot_list.length > 0)
                {
                    $scope.$root.showSelect(
                        {
                            label : 'slot_no',
                            code : 'slot_no',
                            selectCode : $scope.select_slot_no,
                            list : $scope.select_slot_list,
                            confirm : function(item, dialog)
                            {
                                $scope.select_slot_no = item.slot_no;
                                // $scope.$root.showConfirm($filter('translate')('SMT.common.msg.sure_submit'),
                                // function(confirm_alter)
                                // {
                                //     var content = {
                                //         area_no :  $scope.machine_no,
                                //         equipment_no :  $scope.machine_no,
                                //         equipment_state :  $scope.machine_state,
                                //         plot_no :  $scope.plot_no,
                                //         feederlist_no :  $scope.feederlist_no,
                                //         feederlist_ver :  $scope.feederlist_ver,
                                //         feeder_type_no :  $scope.feeder_type_no,
                                //         feeder_no :  $scope.feeder_no,
                                //         feeder_state :  $scope.feeder_state,
                                //         material_no :  $scope.material_no,
                                //         reel_no: $scope.reel_no,
                                //         slot_no: $scope.select_slot_no,
                                //         panel_side:$scope.panel_val
                                //     };
                                //     equipment_reel_set_process(content,function(){
                                //         $scope.phases_index = 0;
                                //         $scope.machine_state = '';
                                //         $scope.feeder_no = '';
                                //         $scope.feeder_state = '';
                                //         $scope.material_no = '';
                                //         $scope.reel_no = '';
                                //         $scope.slot_no = '';
                                //         $scope.select_slot_no = '';
                                //         $scope.select_slot_list = [];
                                //         $scope.$root.showToast($filter('translate')('common.msg.success'));
                                //     });
                                //     confirm_alter.hide();
                                // });
                                dialog.hide();
                            }
                        });
                }
                else
                {
                    $scope.$root.showAlert($filter('translate')('SMT.common.msg.no_slot'));
                }
            }
            //取得料站資料(條列式)
            function get_slot_list()
            {
                let slot_content = {
                    equipment_no:$scope.machine_no,
                    material_no:$scope.material_no,
                    feederlist_no:$scope.feederlist_no,
                    feederlist_ver:$scope.feederlist_ver,
                    panel_side: $scope.panel_val //  (1：正板，2：背板) 
                }
                slot_info_get(slot_content, function(slot_itemList)
                {
                    if(slot_itemList && slot_itemList.length > 0)
                    {
                        $scope.select_slot_list = slot_itemList;
                        $scope.select_slot_no = slot_itemList[0].slot_no;
                    }
                });
            }
            $scope.loadFeederList = function(){
                // 台車為已上料狀態，不可更改料站表
                if($scope.mfu_state_40 != true){
                    $scope.$root.showSelect({
                        label : 'feederlist_ver',
                        code : 'feederlist_ver',
                        selectCode : $scope.feederlist_ver,
                        list : $scope.feederlist,
                        confirm : function(item, dialog){
                            $scope.feederlist_ver = item.feederlist_ver;
                            dialog.hide();
                        }
                    });
                } else {
                    $scope.$root.showAlert($filter('translate')('SMT03.msg.machine_already_feeding_canNot_modify_feederlist_no'));
                };
            };

            function reel_process(itemList){
                // 在庫 0
                if(itemList[0].is_by_lot=='N'){//add by Oliver for M#74017 鑫森海SMT修改 
                    if(itemList[0].state == '0'){
                        $scope.phases_index = 2;
                        $scope.reel_no = itemList[0].reel_no;
                        $scope.material_no = itemList[0].material_no;
                        $scope.material_product_no = itemList[0].product_no;
                        $scope.material_item_spec = itemList[0].item_spec;
                        $scope.mfg_date = itemList[0].mfg_date;
                        $scope.exp_date = itemList[0].exp_date;
                        get_slot_list();
                    // 80 報廢
                    } else if(itemList[0].state == '80'){
                        $scope.$root.showAlert($filter('translate')('SMT.common.msg.reel_scrapped'));
                    // 40 已上料
                    } else if (itemList[0].state == '40'){
                        $scope.$root.showAlert($filter('translate')('SMT.common.msg.reel_already_feeding'));
                    // 60 已上線
                    } else if (itemList[0].state == '60'){
                        $scope.$root.showAlert($filter('translate')('SMT.common.msg.reel_already_online'));
                    // 不存在
                    } else {
                        $scope.$root.showAlert($filter('translate')('SMT.common.msg.no_reel'));
                    };
                }else{
                    if(itemList[0].state == '80'){
                        $scope.$root.showAlert($filter('translate')('SMT.common.msg.reel_scrapped'));
                    }else{
                        $scope.phases_index = 2;
                        $scope.reel_no = itemList[0].reel_no;
                        $scope.material_no = itemList[0].material_no;
                        $scope.material_product_no = itemList[0].product_no;
                        $scope.material_item_spec = itemList[0].item_spec;
                        $scope.mfg_date = itemList[0].mfg_date;
                        $scope.exp_date = itemList[0].exp_date;
                        get_slot_list();
                    }
                }
            }

            // barcode輸入 callback
            function input_barcode_no_callback(barcode){
                $('#toast-panel').css("background-color","#f2ba11");
                if(barcode != ''){
                    // 設備流程
                    if($scope.level_index == 0 && $scope.phases_index == 0){
                        machine_info_get(barcode, function(itemList){
                            // 設備狀態只有 閒置 和 已上料 兩種
                            if(itemList && itemList.length > 0){
                                // 閒置 90
                                if(itemList[0].state == '90'){
                                    $scope.phases_index = 1;
                                    $scope.machine_no = itemList[0].equipment_no;
                                    $scope.machine_state = itemList[0].state;
                                    $scope.area_no = itemList[0].area_no
                                    $scope.is_dispatch = itemList[0].is_dispatch;
                                    $scope.check_forbidden_reel = itemList[0].check_forbidden_reel;//禁用物料管理參數
                                // 已上料 40 → 設備是已上料的狀態，則直接帶入之前user操作系統所記錄的生產批及料站表資料，且不可修改
                                } else if (itemList[0].state == '40'){
                                    $scope.phases_index = 2;
                                    $scope.machine_state_40 = true;
                                    $scope.machine_no = itemList[0].equipment_no;
                                    $scope.machine_state = itemList[0].state;
                                    $scope.plot_no = itemList[0].lot_no;
                                    $scope.plot_product_no = itemList[0].product_no;
                                    $scope.plot_item_spec = itemList[0].item_spec;
                                    $scope.feederlist_no = itemList[0].feederList_no;
                                    $scope.feederlist_ver = itemList[0].feederlist_ver;
                                    $scope.check_forbidden_reel = itemList[0].check_forbidden_reel;//禁用物料管理參數
                                // 不存在
                                } else {
                                    //20200326 modify by Dustdusk for M#67396: 調整訊息內容
                                    $scope.$root.showAlert($filter('translate')('SMT03.msg.machine_state_not_correct', itemList[0]));
                                };
                            } else {
                                $scope.$root.showAlert($filter('translate')('common.msg.no_data'));
                            };
                        });
                    // 生產批流程
                    } else if($scope.level_index == 0 && $scope.phases_index == 1){
                        if($scope.is_dispatch == 0){
                            plot_info_get_dispatch_zero(barcode, function(itemList){
                                if(itemList && itemList.length > 0){
                                    $scope.phases_index = 2;
                                    $scope.plot_no = itemList[0].plot_no;
                                    $scope.plot_product_no = itemList[0].product_no;
                                    $scope.plot_item_spec = itemList[0].item_spec;
                                    $scope.feederlist_no = itemList[0].feederlist_no;
                                    $scope.feederlist_ver = itemList[0].feederlist_ver;
                                    $scope.feederlist = itemList;
                                } else {
                                    $scope.$root.showAlert($filter('translate')('common.msg.no_data'));
                                };
                            })
                        } else if ($scope.is_dispatch == 1){
                            plot_info_get_dispatch_one(barcode, function(itemList){
                                if(itemList && itemList.length > 0){
                                    $scope.phases_index = 2;
                                    $scope.plot_no = itemList[0].plot_no;
                                    $scope.plot_product_no = itemList[0].product_no;
                                    $scope.plot_item_spec = itemList[0].item_spec;
                                    $scope.feederlist_no = itemList[0].feederlist_no;
                                    $scope.feederlist_ver = itemList[0].feederlist_ver;
                                    $scope.feederlist = itemList;
                                } else {
                                    $scope.$root.showAlert($filter('translate')('common.msg.no_data'));
                                };
                            });
                        } else {
                            $scope.$root.showAlert($filter('translate')('SMT.common.msg.process_error'));
                        };
                    // 料站表流程
                    } else if($scope.level_index == 0 && $scope.phases_index == 2) {
                        if($scope.machine_state_40 != true){
                            feederlist_info_get(barcode, function(itemList){
                                if(itemList && itemList.length > 0){
                                    $scope.feederlist = itemList;
                                    $scope.feederlist_no = itemList[0].feederlist_no;
                                    $scope.feederlist_ver = itemList[0].feederlist_ver;
                                } else {
                                    $scope.$root.showAlert($filter('translate')('common.msg.no_data'));
                                };
                            });
                        } else {
                            $scope.$root.showAlert($filter('translate')('SMT03.msg.machine_already_feeding_canNot_modify_feederlist_no'));
                        };
                    // feeder 流程
                    } else if($scope.level_index == 1 && $scope.phases_index == 0) {
                        feeder_info_get(barcode, function(itemList){
                            // 在上料比對功能，在庫狀態和已上料狀態才能成功，其他狀態提示異常
                            if(itemList && itemList.length > 0){
                                // 0 在庫
                                if(itemList[0].state == '0'){
                                    var content = {
                                        feeder_no : itemList[0].feeder_no
                                    };
                                    // 在庫狀態才做檢查
                                    feeder_check_process(content,function(data, response){
                                        if(response.Message != ''){
                                            $scope.$root.showAlert(response.Message);
                                        } else {
                                            $scope.phases_index = 1;
                                            $scope.feeder_type_no = itemList[0].feeder_type_no;
                                            $scope.feeder_no = itemList[0].feeder_no;
                                            $scope.feeder_state = itemList[0].state;
                                        };
                                    });
                                // 40 已上料 → 如果 feeder 是已上料狀態，會同時刷入 feeder 和 捲料(物料)資料
                                } else if(itemList[0].state == '40'){
                                    $scope.phases_index = 2;
                                    $scope.feeder_type_no = itemList[0].feeder_type_no;
                                    $scope.feeder_no = itemList[0].feeder_no;
                                    $scope.feeder_state = itemList[0].state;
                                    $scope.material_no = itemList[0].material_no;
                                    $scope.state = itemList[0].state;
                                    $scope.reel_no = itemList[0].reel_no;
                                    $scope.material_item_spec = itemList[0].item_spec;
                                    $scope.mfg_date = itemList[0].mfg_date;
                                    $scope.exp_date = itemList[0].exp_date;
                                    get_slot_list();
                                // 80 報廢
                                } else if(itemList[0].state == '80'){
                                    $scope.$root.showAlert($filter('translate')('SMT.common.msg.feeder_scrapped'));
                                // 70 送修
                                } else if(itemList[0].state == '70'){
                                    $scope.$root.showAlert($filter('translate')('SMT.common.msg.feeder_repair'));
                                // 50 已上台車
                                } else if (itemList[0].state == '50'){
                                    $scope.$root.showAlert($filter('translate')('SMT.common.msg.feeder_already_feeding'));
                                // 60 已上線
                                } else if (itemList[0].state == '60'){
                                    $scope.$root.showAlert($filter('translate')('SMT.common.msg.feeder_already_online'));
                                // 不存在
                                } else {
                                    $scope.$root.showAlert($filter('translate')('SMT.common.msg.no_feeder'));
                                };
                            } else {
                                $scope.$root.showAlert($filter('translate')('common.msg.no_data'));
                            };
                        });
                    // 物料流程
                    } else if($scope.level_index == 1 && $scope.phases_index == 1) {
                        material_info_get(barcode, function(itemList){
                            // 在庫狀態才能成功，其他狀態提示異常
                            if(itemList && itemList.length > 0){
                                if($scope.disable_control == '1'){ //啟用禁用物料模式
                                    if(itemList[0].forbidden_reel == '1'){
                                        $scope.$root.showAlert($filter('translate')('fordden_msg.forbid_reel'));
                                    }else{
                                        // MSD卡控卡這裡
                                        if((+itemList[0].remain_time) < 0 && itemList[0].remain_time !='-0.1'){
                                            $('#toast-panel').css("background-color","rgb(219, 75, 60)");
                                            $scope.$root.showAlert($filter('translate')('SMT03.msg.MSD_over_time'));
                                            return;
                                        }else if((+itemList[0].remain_time) <= 30 && (+itemList[0].remain_time) > 0){
                                            reel_process(itemList);
                                            $rootScope.showAlertWithoutfocus($filter('translate')('SMT03.msg.MSD_in_a_hurry'));
                                            return
                                        }else if((+itemList[0].remain_time) <= 60 && (+itemList[0].remain_time) > 30){
                                            reel_process(itemList);
                                            $rootScope.showAlertWithoutfocus($filter('translate')('SMT03.msg.MSD_go_to_over_time'));
                                            return
                                        }else{
                                            reel_process(itemList);
                                        }
                                    }
                                }else{
                                    // MSD卡控卡這裡
                                    if((+itemList[0].remain_time) < 0 && itemList[0].remain_time !='-0.1'){
                                        $('#toast-panel').css("background-color","rgb(219, 75, 60)");
                                        $scope.$root.showAlert($filter('translate')('SMT03.msg.MSD_over_time'));
                                        return;
                                    }else if((+itemList[0].remain_time) <= 30 && (+itemList[0].remain_time) > 0){
                                        reel_process(itemList);
                                        $rootScope.showAlertWithoutfocus($filter('translate')('SMT03.msg.MSD_in_a_hurry'));
                                        return
                                    }else if((+itemList[0].remain_time) <= 60 && (+itemList[0].remain_time) > 30){
                                        reel_process(itemList);
                                        $rootScope.showAlertWithoutfocus($filter('translate')('SMT03.msg.MSD_go_to_over_time'));
                                        return
                                    }else{
                                        reel_process(itemList);
                                    }
                                }
                            } else {
                                $scope.$root.showAlert($filter('translate')('common.msg.no_data'));
                            };
                        });
                    // 料站流程
                    } else if($scope.level_index == 1 && $scope.phases_index == 2) {
                        let slot_content = {
                            equipment_no:$scope.machine_no,
                            material_no:$scope.material_no,
                            feederlist_no:$scope.feederlist_no,
                            feederlist_ver:$scope.feederlist_ver,
                            panel_side: $scope.panel_val //  (1：正板，2：背板) 
                        }
                        if(getCheckResult(barcode)){//如果檢核結果為真
                            slot_info_get(slot_content, function(itemList){
                                if(itemList && itemList.length > 0){
                                        $scope.slot_no = barcode;
                                        $scope.select_slot_no = itemList[0].slot_no;
                                        var content = {
                                            area_no :  $scope.machine_no,
                                            equipment_no :  $scope.machine_no,
                                            equipment_state :  $scope.machine_state,
                                            plot_no :  $scope.plot_no,
                                            feederlist_no :  $scope.feederlist_no,
                                            feederlist_ver :  $scope.feederlist_ver,
                                            feeder_type_no :  $scope.feeder_type_no,
                                            feeder_no :  $scope.feeder_no,
                                            feeder_state :  $scope.feeder_state,
                                            material_no :  $scope.material_no,
                                            reel_no: $scope.reel_no,
                                            slot_no: $scope.slot_no,
                                            panel_side:$scope.panel_val
                                        };
    
                                        equipment_reel_set_process(content,function(){
                                            $scope.phases_index = 0;
                                            $scope.machine_state = '';
                                            $scope.feeder_no = '';
                                            $scope.feeder_state = '';
                                            $scope.material_no = '';
                                            $scope.reel_no = '';
                                            $scope.slot_no = '';
                                            $scope.select_slot_no = '';
                                            $scope.select_slot_list = [];
                                            $scope.mfg_date = '';
                                            $scope.exp_date = '';
                                            $scope.$root.showToast($filter('translate')('common.msg.success'));
                                        });
                                    
                                } else {
                                    $scope.$root.showAlert($filter('translate')('common.msg.no_data'));
                                };
                            });
                        }else{
                            $scope.$root.showAlert($filter('translate')('SMT02.msg.slot_no_not_right'));
                        }
                    } else {
                        $scope.$root.showAlert($filter('translate')('SMT.common.msg.process_error'));
                    };
                };
            };
            // 料站資訊取得
            function getCheckResult(barcode){
                if($scope.select_slot_list.length > 0){//檢查可用那些料站口
                    return $scope.select_slot_list.some(function(item){return item.slot_no == barcode;})
                }else{
                    return true;
                }
            }

            // 檢查開窗
            $scope.check = function(){
                var content = {
                    feederlist_no: $scope.feederlist_no,
                    feederlist_ver: $scope.feederlist_ver,
                    feeder_no: $scope.feeder_no,
                    equipment_no:$scope.machine_no,
                    panel_side:$scope.panel_val
                };
                // 取得上料紀錄
                feeding_record_info_get(content, function(data){
                    if(data && data.mfu_check_list_data.length > 0){
                        data.mfu_check_list_data.some(function(item){
                            if((+item.remain_time) <= 0 && item.remain_time != "-0.1"){
                                $rootScope.showAlert($filter('translate')('SMT03.msg.acces_need_to_dry'));
                            }
                        })
                        $scope.feeding_record_list = data.mfu_check_list_data;
                    } else {
                        $scope.feeding_record_list = [];
                    };

                    $MaterialStation.init({
                        data:{
                            plot_no: $scope.plot_no,
                            product_no : $scope.plot_product_no,
                            item_spec : $scope.plot_item_spec
                        },
                        itmeList: $scope.feeding_record_list || [],
                        feeding_record_info_get,
                        content
                    });
                }); 
            };

            // 取得 設備資料
            function machine_info_get(machine_no, callback){
                let content = {
                    EquipmentNo:machine_no
                }
                $MMWService.sendToServer({
                    uri : 'ServicesSMT.Module_SMT.equipment_info_get',
                    content : content,
                    success : function(data){
                        if(callback)
                            callback(data);
                    }
                });
            };

            // 取得 生產批資料 (is_dispatch = 0)
            function plot_info_get_dispatch_zero(plot_no, callback){
                $MMWService.pageNumberInfoGet({
                    page_mode : 'equipment_queue_info_get',
                    query_condition_info:[
                        {column_name:'a.AreaNo', query_mode:'0', value: $scope.area_no, merge_condition_model:'AND'},
                        {column_name:'b.BaseLotNo', query_mode:'0', value: plot_no, merge_condition_model:'AND'}
                    ]
                }, function(itemList){
                    if(callback)
                        callback(itemList);
                });
            };

            // 取得 生產批資料 (is_dispatch = 1)
            function plot_info_get_dispatch_one(plot_no, callback){
                $MMWService.pageNumberInfoGet({
                    page_mode : 'equipment_dispatch_queue_info_get',
                    query_condition_info:[
                        {column_name:'a.EquipmentNo', query_mode:'0', value: $scope.area_no, merge_condition_model:'AND'},
                        {column_name:'b.BaseLotNo', query_mode:'0', value: plot_no, merge_condition_model:'AND'}
                    ]
                }, function(itemList){
                    if(callback)
                        callback(itemList);
                });
            };

            // 取得 料站表資料
            function feederlist_info_get(feederlist_no, callback){
                $MMWService.pageNumberInfoGet({
                    page_mode : 'feederlist_info_get',
                    query_condition_info:[
                        {column_name:'b.FeederListNo', query_mode:'0', value: feederlist_no, merge_condition_model:'AND'},
                        {column_name:'BaseLotNo', query_mode:'0', value: $scope.plot_no, merge_condition_model:'AND'},
                        {column_name:'c.EquipmentNo', query_mode:'0', value: $scope.machine_no, merge_condition_model:'AND'},
                    ]
                }, function(itemList){
                    if(callback)
                        callback(itemList);
                });
            };

             // 取得 Feeder資料
             function feeder_info_get(feeder_no, callback){
                $MMWService.pageNumberInfoGet({
                    page_mode : 'feeder_info_get',
                    query_condition_info:[
                        {column_name:'FeederNo', query_mode:'0', value: feeder_no, merge_condition_model:'AND'},
                    ]
                }, function(itemList){
                    if(callback)
                        callback(itemList);
                });
            };

            // Feeder檢查
            function feeder_check_process(content, callback){
                $MMWService.sendToServer({
                    uri : 'ServicesSMT.Module_SMT.feeder_mfu_check_process',
                    content : content,
                    success : function(data, response){
                        if(callback)
                            callback(data, response);
                    }
                });
            };

            // 取得 捲料資料
            function material_info_get(reel, callback){
                 //20200702 modify by Oliver for 鑫森海SMT修正服務
                 let content = {
                    reel_no:reel,
                    feederlist_no:$scope.feederlist_no,
                    feederlist:$scope.feederlist,
                    feederlist_ver:$scope.feederlist_ver,
                    check_forbidden_reel:$scope.check_forbidden_reel
                }
                $MMWService.sendToServer({
                    uri : 'ServicesSMT.Module_SMT.reel_info_get',
                    content : content,
                    success : function(data){
                        if(callback)
                            callback(data);
                    }
                });
            };

            // 料站資訊取得
            function slot_info_get(content,callback){
                $MMWService.sendToServer({
                    uri : 'ServicesSMT.Module_SMT.uncomplete_slot_info_get',
                    content : content,
                    success : function(data){
                        if(data.slot_list.length == 0){
                            $scope.$root.showAlert($filter('translate')('SMT02.msg.slot_list_none'));                    
                        }else{
                            if(callback)
                                callback(data.slot_list);
                        }
                    }
                });
            };

            // 比對料站表並回寫資料
            function equipment_reel_set_process(content, callback){
                $MMWService.sendToServer({
                    uri : 'ServicesSMT.Module_SMT.equipment_reel_set_process',
                    content : content,
                    success : function(data){
                        if(callback)
                            callback(data);
                    }
                });
            };

            // 點擊檢查 取得上料紀錄
            function feeding_record_info_get(content, callback){
                $MMWService.sendToServer({
                    uri : 'ServicesSMT.Module_SMT.mfu_check_info_get',
                    content : content,
                    success : function(data){
                        if(callback)
                            callback(data);
                    }
                });
            };

            $scope.input_PDA_barcode = function(event){
                if (event.keyCode == 13) {
                    element_barcode_no.blur();
                    input_barcode_no_callback($scope.barcode)
                    $scope.barcode = '';
                } else {
                    $scope.barcode = $scope.barcode || '';
                }
            }

            //20200914 modify by Dustdusk for M#: 增加
            function makeBarcodeInput(el) {
                var _input = el.getElementsByClassName('barcode_input')[0];
                //var _mask = el.getElementsByClassName('barcode_mask')[0];
                el.focus = function () {
                    //e.preventDefault();
                    //_mask.click();
                    el.click();
                }
                el.addEventListener('click', function (e) {
                    e.preventDefault();
                    //_input.value = '';
                    if (document.activeElement !== _input)
                        _input.focus();
                });
                _input.addEventListener('focus', function (e) {
                    e.preventDefault();
                    setTimeout(function () {
                        _input.removeAttribute('readonly');
                    }, 200);
                });
                _input.addEventListener('blur', function (e) {
                    e.preventDefault();
                    _input.setAttribute('readonly', 'readonly');
                });
            }
        }
    ];
});
